package com.itheima.ai.service.Impl;

import com.itheima.ai.service.ChatHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
public class ChatHistoryServiceImpl implements ChatHistoryService {
   @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public void saveHistory(String type, String chatId) {

        redisTemplate.opsForSet().add(type, chatId);
    }


    @Override
    public List<String> getHistory(String type) {
        Set<String> members = redisTemplate.opsForSet().members(type);
        return new ArrayList<>(members);
    }
}
